<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>保险支公司 管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label{overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">保险公司名称</div>
                    <div class="field">
                        <input name="compPid" id="compPid" data-value="${compPid}" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支公司名称</div>
                    <div class="field">
                        <input name="compNm" id="compNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支公司所属地</div>
                    <div class="field">
                        <input name="rgnPrCd" id="rgnPrCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
				<div class="fieldBox">
                    <div class="label">购买方式</div>
                    <div class="field">
                        <input name="buyWayCd" id="buyWayCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <sys:funcAuth resCd="createInsSubComp">
                        <span id="addBtn" class="sq-button sq-button-round">新增</span>
                        <span id="delBtn" class="sq-button sq-button-round">删除</span>
                        <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                    </sys:funcAuth>
                    <sys:funcAuth resCd="createCompNotMyChn">
                        <span id="addNotMyChnBtn" class="sq-button sq-button-round">非我司渠道</span>
                        <span id="modifyOtherChnBtn" class="sq-button sq-button-round">非我司渠道修改</span>
                    </sys:funcAuth>
                    <sys:funcAuth resCd="insSubCompApply">
                        <span id="processBtn" class="sq-button sq-button-round">渠道审核</span>
                    </sys:funcAuth>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            parms:{compLvl:2,compPid:'${compPid}'},
            url: '<%=path%>/insurance/insCompInfo/initList.do',
            method: 'get',
            columns: [
                {display: '支公司名称', name: 'compNm', minWidth: 200, align: 'left', enabledSort: true},
                {display: '省份', name: 'rgnPrNm', width: 100, align: 'left', enabledSort: true},
                {display: '城市', name: 'rgnCyNm', width: 100, align: 'left', enabledSort: true},
                {display: '保险公司名称', name: 'compPidNm', minWidth: 200, align: 'left', enabledSort: true},
                {display: '渠道', name: 'chnCdNm', width: 100, align: 'left', enabledSort: true},
                {display: '购买方式', name: 'buyWayCdNm', width: 100, align: 'left', enabledSort: true},
                {display: '操作', name: '', width: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='<a class="sq-button-hasicon" href="javascript:;" onclick="searchSubDtl(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_1"></i>查看</a>';
                        return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true
        });
        grid.setHeight(100);

        $("#rgnPrCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#compPid").ligerComboBox({
            valueField: 'id',
            textField: 'compNm'
        });
        $("#buyWayCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#searchBar").ligerForm();

        liger.get("compPid").setData(${insCompList});
        liger.get("buyWayCd").setData(${buyWayCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
        	grid.removeParm("compPid");
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "compPid": " ",
                "rgnPrCd": " ",
               	"buyWayCd": " "
            });
        });

        var callback = function () {
            grid.reload();
        };

        /* 新增 我司+非我司 */
        $("#addBtn").click(function (event) {
            Add_navTab("InsCompInfo_01", "新增保险支公司", '<%=path%>/insurance/insCompInfo/toAddPage.do?compLvl=2', callback);
        });
        /* 新增 非我司 */
        $("#addNotMyChnBtn").click(function (event) {
            Add_navTab("InsCompInfo_N_01", "新增保险支公司", '<%=path%>/insurance/insCompInfo/toAddPage.do?compLvl=2&chnCd=2', callback);
        });

        /* 新增 */
        $("#processBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if (selectedRows[0].chnCd == 1) {
                $.ligerDialog.SQalert({content: "请选择非我司渠道支公司发起流程", SQ_type: "warning"});
                return;
            }

            var _id = selectedRows[0].id;
            Add_navTab("InsCompInfo_03", "发起流程", '<%=path%>/insurance/insCompInfo/toProcessPage.do?flag=0&compLvl=2&id=' + _id, callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            var chnCd=selectedRows[0].chnCd;
            Add_navTab('InsCompInfo_2' + _id, "修改保险支公司", '<%=path%>/insurance/insCompInfo/toModifyPage.do?compLvl=2&id=' + _id+'&chnCd='+chnCd, callback);
        });

        /* 修改 */
        $("#modifyOtherChnBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            var chnCd=selectedRows[0].chnCd;
            if(chnCd==1){
                $.ligerDialog.SQalert({content: "我司渠道支公司不能修改", SQ_type: "warning"});
                return;
            }
            Add_navTab('InsCompInfo_2' + _id, "修改保险支公司", '<%=path%>/insurance/insCompInfo/toModifySubCompPage.do?compLvl=2&id=' + _id+'&chnCd='+chnCd, callback);
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insCompInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

        //发送请求获取省级区域
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '<%=path%>/system/sysRegion/getProvinceRegion.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var seltPr = liger.get("rgnPrCd");
                    seltPr.setData(msg.data);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

    });

    //查看
    function searchSubDtl(id){
        Add_navTab("InsCompInfo_D_"+id, "保险支公司详情", '<%=path%>/insurance/insCompInfo/toCompDtlPage.do?id=' + id, null);
    }

</script>

</body>
</html>
